package net.wendal.base.type;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

/**
 * Created by y on 2017/2/8.
 */
public class Part {

    public String toString() {
        return getClass().getSimpleName();
    }

    static List<Factory<? extends Part>> partFactories = new ArrayList<Factory<? extends Part>>();

    static {
        partFactories.add(new FuelFilter.Factory());
        partFactories.add(new FanBelt.Factory());
    }

    private static Random random = new Random(47);

    public static Part createRandom() {
        int i = random.nextInt(partFactories.size());
        return partFactories.get(i).create();
    }
}


class RegisteredFactories {
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++)
            System.out.println(Part.createRandom());
    }
}

interface Factory<T> {
    T create();
}

class Filter extends Part {

}

class FuelFilter extends Filter {

    public static class Factory implements net.wendal.base.type.Factory<FuelFilter> {

        @Override
        public FuelFilter create() {
            return new FuelFilter();
        }
    }
}

class Belt extends Part {

}

class FanBelt extends Belt {
    public static class Factory implements net.wendal.base.type.Factory<FanBelt> {


        @Override
        public FanBelt create() {
            return new FanBelt();
        }
    }
}
